using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Newtonsoft.Json.Linq;
// using Quobject.SocketIoClientDotNet.Client;

class LogReporter : API.ILogReport
{
    // [Inject]
    public API.IStartOption StartOption { get; set; }
    public mb.ILogger logger { get; set; }

    //-/////////////////////////////////////////////
    Socket socket;
    List<string> bufferdLogs = new List<string>();

    public void Stop()
    {
        if (socket != null)
            socket.Close();
    }

    public void Start()
    {
        Log.Logs("logreport start", StartOption);
        var url = StartOption.GetValue<string>("reportlog");
        if (url != null)
        {
            StartReportLog(url);
        }
    }

    void StartReportLog(string url)
    {
        Log.Logs("start report log", url);
        if (!url.StartsWith("ws://") && !url.StartsWith("http://"))
            url = "ws://" + url;

        HookAppLog();
        socket = IO.Socket(url);
        socket.On(Socket.EVENT_CONNECT, () =>
        {
            Log.Logs("connected");
        });
        socket.On(Socket.EVENT_DISCONNECT, () =>
        {
            Log.Logs("disconnect");
        });
        socket.On("action", (data) =>
        {
            Log.Logs("recv action", data);
        });
    }
}